package com.authine.cloudpivot.ext.dto.model.settle;

import cn.hutool.core.bean.BeanUtil;
import com.authine.cloudpivot.ext.Enum.ContractPaymentType;
import com.authine.cloudpivot.ext.Enum.SettleBusinessType;
import com.authine.cloudpivot.ext.Enum.SettleStatus;
import com.authine.cloudpivot.ext.Enum.SettleType;

import com.authine.mvp.app.launcher.domain.SelectorFormat;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 结算单
 *
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Settle implements Serializable {

    private String id;
    /**
     * 关联ID(退款对应的收款的ID)
     */
    private String reference_id;
    /**
     * 付款组织信息
     */
    private SelectorFormat purchase_organization_id;
    private String purchase_organization_name;
    /**
     * 收款组织信息
     */
    private SelectorFormat sale_organization_id;
    private String sale_organization_name;

    /**
     * 平台组织ID
     */
    private String platform_organization_id;
    /**
     * 申请人信息
     */
    private String apply_member_id;
    private String apply_member_name;
    /**
     * 确认信息
     */
    private String confirm_member_id;
    private String confirm_member_name;
    /**
     * 申请时间
     */
    private Date apply_time;
    /**
     * 付款时间
     */
    private Date payment_time;
    /**
     * 确认时间
     */
    private Date confirm_time;
    /**
     * 结算金额(不包含服务费)
     */
    private BigDecimal total;
    /**
     * 可核销金额
     */
    private BigDecimal write_off_total;

    /**
     * 核销状态 0=可核销，1=已核销
     */
    private String woffNow;
    /**
     * 已退款金额（Done和Approving状态的）
     * 该结算单关联的退款单的总金额，只做验证用，不是该结算单的退款金额
     */
    private BigDecimal refund_total;
    /**
     * 状态
     */
    private SettleStatus statuss;
    /**
     * 结算业务类型
     */
    private SettleBusinessType business_type;
    /**
     * 自定义垫资服务费结算比例
     */
    private BigDecimal interest_rate;
    /**
     * 自定义平台服务费结算比例
     */
    private BigDecimal platform_rate;

    /**
     * 垫资费
     */
    private BigDecimal interest;

    /**
     * 平台服务费
     */
    private BigDecimal platform;

    /**
     * 支付类型
     */
    private SettleType type;
    private String bank_serial_number;
    /**
     * 银行流水图片
     */
    private String bank_serial_image;
    /**
     * 采购组织抬头
     */
    private String purchase_name;
    /**
     * 采购方信息
     */
    private String purchase_bank_info;
    private String purchase_bank_no;
    private String purchase_bank_account;
    private String purchase_phone;
    private String purchase_memo;
    /**
     * 销售方信息
     */
    private String sale_bank_info;
    private String sale_bank_no;
    private String sale_bank_account;
    private String sale_phone;
    private String sale_memo;
    /**
     * 发票号码
     */
    private String invoice_number;
    /**
     * 扩展信息
     */
    private String extends_attr;
    /**
     * 是否代购
     */
    private boolean contract;
    /**
     * 代购收款时收款类型
     */
    private ContractPaymentType contract_payment_type;
    /**
     * 服务费发票编号
     */
    private String invoice_service_ids;

    private Date createdTime;

    /**
     * 结算明细
     */
    @Schema(description = "结算明细")
    private List<SettleDetail> settleDetailList;

    /**
     * 结算详情（发票维度）
     */
    @ApiModelProperty("结算详情（发票维度）")
    private List<SettleInvoiceDetail> settleInvoiceDetailList;


    public String getBusiness_type(){
        return this.business_type.name();
    }

    public String getType(){
        return this.type.name();
    }

    public SettleType getTypeEum(){
        return this.type;
    }

    public String getContract_payment_type(){
        return this.contract_payment_type == null ? null : this.contract_payment_type.name();
    }

    public Map<String, Object> beanToMap(){
        Map<String, Object> map = BeanUtil.beanToMap(this);
        map.put("contract_payment_type", this.getContract_payment_type());
        map.put("type", this.getType());
        map.put("business_type", this.getBusiness_type());
        map.put("statuss", this.getStatuss().name());
        return map;
    }
}
